﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using T2.WebSecurity;

namespace T2.WebSecurity.Test
{
    [TestClass]
    public class EncryptionTest
    {
        [TestMethod]
        public void TestMethod()
        {
            string inputPass = "password1";
            string sharedSecret = "answer1";
            string salt = "11110000";
            string salt2 = "00001111";

            T2.WebSecurity.CryptoHelper ch = new CryptoHelper();
            string passEnc = ch.EncryptStringAES(inputPass, sharedSecret, salt2);

            string passStr = ch.DecryptStringAES(passEnc, sharedSecret, salt2);
            Assert.AreEqual(inputPass, passStr);
        }

        [TestMethod]
        public void TestMethod2()
        {
            string[] inputPass = {"password1","duminda324ff","sithila809",
                                 "this is a fun time","123a 6546a 456  654",
                                 "letanotherdaytrythisandgohome"};
            List<string> result = new List<string>();

            string sharedSecret = "answer1";
            string sharedSecret2 = "what is your mothers maiden name?";
            
            string salt = "11110000";   // salt is a must
            string salt2 = "salt";//should be atleast 8bytes

            T2.WebSecurity.CryptoHelper ch = new CryptoHelper();
            foreach (var item in inputPass)
            {
                string passEnc = ch.EncryptStringAES(item, sharedSecret2, salt);
                string passDec = ch.DecryptStringAES(passEnc, sharedSecret2, salt);
                result.Add(passDec);
            }
            
            string[] actualPass = result.ToArray();
            
            CollectionAssert.AreEqual(inputPass, actualPass);
        }
    }
}
